use serde::{Deserialize, Serialize};

use crate::database::DataSource;

#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
pub struct GetDataSourceOptions {
    pub class_identifier: Option<String>,
    pub default_datasource: Option<DataSource>,
}

#[async_trait::async_trait]
pub trait DataSourceProvider {
    async fn get_datasource_id(&self, options: GetDataSourceOptions) -> anyhow::Result<u32>;

    async fn get_datasource(&self, options: GetDataSourceOptions) -> anyhow::Result<DataSource>;

    async fn set_default_datasource(&mut self, default_ds: DataSource) -> anyhow::Result<()>;
}

impl GetDataSourceOptions {
    pub fn with_class_identifier(class_identifier: &String) -> GetDataSourceOptions {
        GetDataSourceOptions {
            class_identifier: Some(class_identifier.clone()),
            default_datasource: None,
        }
    }
}
